package com.springboot.config;

import com.springboot.common.JacksonObjectMapper;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import java.util.List;


@Configuration
public class WebMvcConfig  implements WebMvcConfigurer {
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
         registry.addResourceHandler("/backend/**").addResourceLocations("classpath:/backend/");
        registry.addResourceHandler("/front/**").addResourceLocations("classpath:/front/");
    }

    /**
     * 扩展消息转换器
     * @param converters the list of configured converters to be extended
     */
    @Override
    public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
        // 添加新的消息转换器
        MappingJackson2HttpMessageConverter  messageConverter = new MappingJackson2HttpMessageConverter();
        //设置对象转换器，底层使用jackson将我们的java对象转换为json字符串
         messageConverter.setObjectMapper(new JacksonObjectMapper());
      //将我们上面的消息转换器添加到mvc框架的转换器集合中
        converters.add(0, messageConverter);
    }


}
